package com.chushouya.product.service.common.impl;

import com.general.framework.core.lang.Longs;
import com.chushouya.product.dao.entity.ClothesProductEntity;
import com.chushouya.product.dao.repository.ClothesProductRepository;
import com.chushouya.product.service.common.ClothesProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * 旧衣商品通用服务实现
 */
@Service
@Slf4j
public class ClothesProductServiceImpl implements ClothesProductService {

    @Resource
    private ClothesProductRepository clothesProductRepository;

    @Override
    public ClothesProductEntity getProductByCode(Long provinceCode) {
        if (Longs.isNullOrZero(provinceCode)) {
            log.warn("地区编码为空，返回null");
            return null;
        }
        
        ClothesProductEntity product = clothesProductRepository.selectByCode(provinceCode);
        if (Objects.isNull(product)) {
            log.warn("未找到地区编码为{}的旧衣商品", provinceCode);
            return null;
        }
        return product;
    }
}
